﻿using FinalPointSet.Model.Constant;
using ICSharpCode.AvalonEdit.Highlighting;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using MessageBox = System.Windows.Forms.MessageBox;

namespace FinalPointSet.View.Dialog
{
    /// <summary>
    /// FieldDialog.xaml 的交互逻辑
    /// </summary>
    public partial class FieldInputDialog : Window
    {
        public string InputValue { get; set; } = string.Empty;
        public FieldInputDialog()
        {
            InitializeComponent();
        }
        public FieldInputDialog(string inputValue, IHighlightingDefinition? highlightingDefinition)
        {
            InitializeComponent();
            InputValue = inputValue;
            fieldEditor.Text = InputValue;
            fieldEditor.SyntaxHighlighting = highlightingDefinition;
        }
        private void OnOKButtonClick(object sender, RoutedEventArgs e)
        {
            InputValue = fieldEditor.Text;
            //校验输入
            if (string.IsNullOrEmpty(InputValue) || Regex.Replace(InputValue, @"\s", "").Length == 0)
            {
                MessageDialog.Pop(Config.APP_Name_CN, "输入的字段不能为空");
                return;
            }

            //返回对话框确认结果
            try
            {
                DialogResult = true;
            }
            catch (System.InvalidOperationException)
            {
                System.Diagnostics.Debug.Print("当前窗口不是以对话框形式出现,不设置对话框返回状态");
            }
            Close();
        }
        private void OnExitButtonClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
        private void OnClearButtonClick(object sender, RoutedEventArgs e)
        {
            fieldEditor.Clear();
        }
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }
    }
}
